package com.factors.DataClean;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;

import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.*;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;

public class PerformanceDriver {
    public static void main(String[] args) throws Exception{

        //指定hdfs相关参数
        Configuration conf = new Configuration();
        Job job = Job.getInstance(conf);

        //设置jar包所在路径
        job.setJarByClass(PerformanceDriver.class);

        //设置mapper类
        job.setMapperClass(PerformanceMapper.class);
        job.setNumReduceTasks(0);

        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(NullWritable.class);

        //指定输入输出的解析类
        job.setInputFormatClass(TextInputFormat.class);
        job.setOutputFormatClass(TextOutputFormat.class);

        //本地路径
        FileInputFormat.addInputPath(job,new Path("input/StudentPerformanceFactors.csv"));
        FileOutputFormat.setOutputPath(job,new Path("Data"));

        //提交任务
        boolean waitForCompletion = job.waitForCompletion(true);

        Counters counters = job.getCounters();
        Counter counter = counters.findCounter("DeleteCounter","deleted");
        long value = counter.getValue();
        System.out.println("共删除的数据条数：" + value);
        System.exit(waitForCompletion ? 0 : 1);



    }

}


